//
// Created by 21126 on 2023/5/18.
//

#ifndef CLION_TEST_U2_I2C_H
#define CLION_TEST_U2_I2C_H

#include <linux/i2c-dev.h>
#include <linux/i2c.h>

#define I2C_DEV_NAME_BASE   "/dev/i2c-"

#define WRITE 0
#define READ 1

#define I2C_DEV_NO_START		2
#define I2C_DEV_NUM				2

typedef struct{
    int  fd;
    unsigned char addr;
    unsigned char flag;
} i2c_addr_def;


int i2c_open(char *dev_name);
void i2c_close(int fd);
int i2c_detect(int fd, unsigned char *addrArray, int num, unsigned char *addr);
int i2c_write_cmd(int fd, unsigned char slave_address, unsigned char cmd);
int i2c_write_byte(int fd, unsigned char slave_address, unsigned char reg_address, unsigned char value);
int i2c_write_bytes(int fd, unsigned char slave_address, unsigned char reg_address, unsigned char *values, int num_byte);
int i2c_read_bytes(int fd, unsigned char slave_address, unsigned char reg_address, unsigned char *buffer, int num_byte);
int i2c_read_bytes_16addr(int fd, unsigned char slave_address, __u16 reg_address, unsigned char *buffer, int num_byte);
__s32 i2c_smbus_access(int file, char read_write, unsigned char command, int size, union i2c_smbus_data *data);
__s32 i2c_smbus_write_quick(int file, unsigned char value);
__s32 i2c_smbus_read_byte(int file);


#endif //CLION_TEST_U2_I2C_H
